﻿//-----------------------------------------------------------------------
// <copyright file="ResourceLoader.cs" company="In The Hand Ltd">
//     Copyright © 2013-14 In The Hand Ltd. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System.Resources;

namespace InTheHand.ApplicationModel.Resources
{
    public sealed class ResourceLoader
    {
        private static ResourceLoader instance;

        public static ResourceLoader GetForCurrentView()
        {
            if (instance == null)
            {
                // the trick is the logic to find the default resource set. this assumes using the Resources.AppResources generated by WP8 templates
                instance = new ResourceLoader(new ResourceManager(System.Windows.Deployment.Current.EntryPointType.Substring(0, System.Windows.Deployment.Current.EntryPointType.LastIndexOf('.')) + "Resources.AppResources", System.Reflection.Assembly.Load(System.Windows.Deployment.Current.EntryPointAssembly)));
            }

            return instance;
        }

        private ResourceManager resourceManager;
        
        private ResourceLoader(ResourceManager manager)
        {
            this.resourceManager = manager;
        }

        public string GetString(string resource)
        {
            return this.resourceManager.GetString(resource);
        }
    }
}
